<?php
// +----------------------------------------------------------------------
// | Author: fl 365581323@qq.com
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Db;
class Common extends Controller{
    // Request实例
    // protected $request;
    public function __construct(){
		parent::__construct(); // 调用父类的构造函数必须显示的使用parent调用父类构造函数
		// 统计品牌下的商品数
		$brand=Db::name('brand')->select();
        foreach ($brand as $val) {
            $gnum=Db::name('goods')->where("gbrand=".$val['bid'])->count();
            if($gnum){
                $data =array(
                    'bnum' => $gnum
                    );
                $list=Db::name('brand')->where("bid=".$val['bid'])->update($data);
            }
        }
        //统计商品的规格数
        $goods=Db::name('goods')->select();
        foreach ($goods as $val) {
        	$specsnum=Db::name('specs')->where("sgoods=".$val['gid'])->count();
        	if($specsnum){
        		$data =array(
                    'gspec' => $specsnum
                    );
        	$list=Db::name('goods')->where("gid=".$val['gid'])->update($data);
        	}
        }
		if(!session('?aid')){
			$this->error("您没有登录！请登录",'Login/index');
			die;
		}
	}
	
}